package com.youthburin.base.util;

import java.io.Serializable;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

public class DwzCondition implements Serializable {
	private static final long serialVersionUID = 1L;
	private String name;
	private String value;
	private Operation op;

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public Operation getOp() {
		return op;
	}

	public void setOp(Operation op) {
		this.op = op;
	}

	public enum Operation {
		/** 等于 */
		EQUALS("eq"),
		/** 不等 */
		NOTEQUALS("ne"),
		/** 小于 */
		LESS("lt"),
		/** 小于等于 */
		LESSOREQUALS("le"),
		/** 大于 */
		GREATER("gt"),
		/** 大于等于 */
		GREATEROREQUALS("ge"),
		/** 开始于 */
		STARTSWITH("bw"),
		/** 结束于 */
		ENDSWITH("ew"),
		/** 包含 */
		CONTAINS("cn");
		private final String value;

		private Operation(String value) {
			this.value = value;
		}

		public String getValue() {
			return this.value;
		}

		public static String toCode(Operation compare) {
			return compare.getValue();
		}

		public static Operation fromCode(String code) {
			Operation[] ops = Operation.values();
			for (Operation op : ops) {
				if (StringUtils.equals(op.value, code))
					return op;
			}
			return null;
		}
	}
}